package com.myCompany.edu.realtime.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;

public class DateUtils {
    public static String toDateTime(long ts) {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(ts);
    }


    public static Long dateToTs(String date) throws ParseException {
        // 把年月日转成毫秒值
        return new SimpleDateFormat("yyyy-MM-dd").parse(date).getTime();
    }

    public static long dateTimeToTs(String dateTime) throws ParseException {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateTime).getTime();
    }

    /*public static void main(String[] args) throws ParseException {
        System.out.println(dateToTs("2022-01-01"));
    }*/
}
